function remove (arr, item) {
    if(!arr.length){return}
    const index = arr.indexOf(item)
    if(index > -1){
        return arr.splice(index, 1)
    }
}
// 发布订阅
export default class Dep {
    constructor() {
       this.subs = [] 
    }
    addSub(sub){
        this.subs.push(sub)
    }
    removeSub(sub){
        remove(this.subs, sub)
    }
    depend(){
        if(window.target){
            this.addSub(window.target)
        }
    }
    notify(){
        const subs = this.subs.slice()
        for(let k in subs){
            subs[k].update()
        } 
    }
}